package com.bigkoo.convenientbanner;

import com.bigkoo.convenientbanner.holder.TaskHolder;

import java.lang.ref.WeakReference;

/**
 * @author QiQi
 * @ClassName: AdSwitchTask
 * @date 2018/9/11
 * @description
 */
class AdSwitchTask implements Runnable {

    private final WeakReference<TaskHolder> reference;

    AdSwitchTask(TaskHolder convenientBanner) {
        this.reference = new WeakReference<>(convenientBanner);
    }

    @Override
    public void run() {
        TaskHolder convenientBanner = reference.get();

        if (convenientBanner != null) {
            if (convenientBanner.getViewPager() != null && convenientBanner.getTurning()) {
                int page = convenientBanner.getViewPager().getCurrentItem() + 1;
                convenientBanner.getViewPager().setCurrentItem(page);
                convenientBanner.postDelay(convenientBanner.getTask(), convenientBanner.getRunTime());
            }
        }
    }
}
